import 'dart:async';

import 'package:flutter/material.dart';

const _locale_en = Locale("en", "US");
const _locale_zh = Locale("zh", "CN");
const _locale_ug = Locale("ug", "CN");

Iterable<Locale> get localizations => [_locale_ug, _locale_en, _locale_zh];

class AppLocalizationDelegate extends LocalizationsDelegate<AppLocalizations> {
  const AppLocalizationDelegate();
  @override
  bool isSupported(Locale locale) =>
      localizations.map((it) => it.languageCode).contains(locale.languageCode);

  @override
  Future<AppLocalizations> load(Locale locale) async =>
      Future(() => AppLocalizations(locale));

  @override
  bool shouldReload(LocalizationsDelegate<AppLocalizations> old) => true;
}


class AppLocalizations {
  Locale locale;

  AppLocalizations(this.locale);

  static AppLocalizations of(BuildContext context) =>
//      Localizations.of<AppLocalizations>(context, AppLocalizations);
  AppLocalizations(_locale_ug);

  static String get _ug => _locale_ug.languageCode;

  static String get _en => _locale_en.languageCode;

  static String get _zh => _locale_zh.languageCode;

  var _strings = <String, List<MapEntry<String, String>>>{
    "fontFamilyOfMain": [
      MapEntry(_ug, "ukij-cjk"),
      MapEntry(_zh, "ukij-cjk"),
      MapEntry(_en, "ukij-cjk"),
    ],
    "fontFamilyOfTitle": [
      MapEntry(_ug, "ukij-bom"),
      MapEntry(_zh, "ukij-bom"),
      MapEntry(_en, "ukij-bom"),
    ],
    "rtl": [
      MapEntry(_ug, "true"),
      MapEntry(_zh, "false"),
      MapEntry(_en, "false"),
    ],
    "signin_title": [
      MapEntry(_ug, "خۇش كىلىپسىز"),
      MapEntry(_en, "Welcome"),
      MapEntry(_zh, "欢迎"),
    ],
    "your_account_name": [
      MapEntry(_ug, "ھىسابات نامىڭىز"),
      MapEntry(_en, "Your account name"),
      MapEntry(_zh, "账号"),
    ],
    "your_account_password": [
      MapEntry(_ug, "ھىسابات پارولىڭىز"),
      MapEntry(_en, "Your account Password"),
      MapEntry(_zh, "密码"),
    ],
    "or": [
      MapEntry(_ug, "ياكى"),
      MapEntry(_en, "or"),
      MapEntry(_zh, "或"),
    ],
    "create_your_account": [
      MapEntry(_ug, "ئۆزىڭىزنىڭ ھىساباتىنى قۇرۇڭ"),
      MapEntry(_en, "Create your account."),
      MapEntry(_zh, "创建您的账号"),
    ],
    "your_account_name_hint": [
      MapEntry(_ug, "ھىسابات نامىڭىزنى بۇ يەرگە كىرگۈزۈڭ"),
      MapEntry(_en, "Your account name here"),
      MapEntry(_zh, "请这里输入账号"),
    ],
    "your_account_password_hint": [
      MapEntry(_ug, "ھىسابات پارولىڭىزنى بۇ يەرگە كىرگۈزۈڭ"),
      MapEntry(_en, "Your account password here."),
      MapEntry(_zh, "请这里输入密码"),
    ],
    "signin": [
      MapEntry(_ug, "كىرىڭ"),
      MapEntry(_en, "SignIn"),
      MapEntry(_zh, "登陆"),
    ],
  };

  String _getResolvedString(String key) => _strings[key].singleWhere((item) => item.key == locale.languageCode).value;

  bool get isRtl => _getResolvedString("rtl") == "true";
  String  get fontFamilyOfMain => _getResolvedString("fontFamilyOfMain");
  String  get fontFamilyOfTitle => _getResolvedString("fontFamilyOfTitle");
  TextDirection get textDirection => isRtl ? TextDirection.rtl : TextDirection.ltr;

  String get signInTitle => _getResolvedString("signin_title");
  String get accountName => _getResolvedString("your_account_name");
  String get accountNameHint => _getResolvedString("your_account_name_hint");
  String get accountPassword => _getResolvedString("your_account_password");
  String get accountPasswordHint => _getResolvedString("your_account_password_hint");
  String get or => _getResolvedString("or");
  String get createYourNewAccount => _getResolvedString("create_your_account");
  String get signIn => _getResolvedString("signin");
}

